package web.suzy.oj.dao.user.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import web.suzy.oj.dao.user.UserInfoEntityService;
import web.suzy.oj.mapper.UserInfoMapper;
import web.suzy.oj.pojo.dto.RegisterDTO;
import web.suzy.oj.pojo.entity.user.UserInfo;
import web.suzy.oj.utils.Constants;
import web.suzy.oj.utils.RedisUtils;

import java.util.List;

/**
 * YangSuzy 软件工作室
 * 类名: UserInfoEntityServiceImpl
 * 描述: 用户信息表实体 dao层服务实现类
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/11/9 12:49
 */
@Service
public class UserInfoEntityServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoEntityService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Autowired
    private RedisUtils redisUtils;

    /**
     * 方法名: addUser
     * 描述: 添加用户
     *
     * @param registerDto 注册用户数据传输对象
     * @return java.lang.Boolean
     * @date 2022/11/9 12:50
     * @auther YangSuzy
     **/
    @Override
    public Boolean addUser(RegisterDTO registerDto) {
        return userInfoMapper.addUser(registerDto) == 1;
    }

    /**
     * 方法名: getSuperAdminUidList
     * 描述: 获取超级管理员 UID列表
     *
     * @return java.util.List<java.lang.String>
     * @date 2022/11/9 12:52
     * @auther YangSuzy
     **/
    @Override
    public List<String> getSuperAdminUidList() {
        //查询缓存中是否已有列表
        String cacheKey = Constants.Account.SUPER_ADMIN_UID_LIST_CACHE.getCode();
        List<String> superAdminUidList = (List<String>) redisUtils.get(cacheKey);
        //否则从数据库中查询并设置缓存
        if (superAdminUidList == null) {
            superAdminUidList = userInfoMapper.getSuperAdminUidList();
            redisUtils.set(cacheKey, superAdminUidList, 12 * 3600);
        }
        return superAdminUidList;
    }

    /**
     * 方法名: getProblemAdminUidList
     * 描述: 获取题目管理员 UID列表
     *
     * @return java.util.List<java.lang.String>
     * @date 2022/11/9 12:53
     * @auther YangSuzy
     **/
    @Override
    public List<String> getProblemAdminUidList() {
        return userInfoMapper.getProblemAdminUidList();
    }
}
